//
//  MSMeQRcodeController.m
//  觅尚
//
//  Created by No.8 on 2019/4/2.
//  Copyright © 2019 No.8. All rights reserved.
//

#import "MSMeQRcodeController.h"

@interface MSMeQRcodeController ()
{
    CustomNavigationBar *naviagtionBar;
}
/** 头像*/
@property(nonatomic,strong)UIImageView *photoIMG;

/** 姓名*/
@property(nonatomic,strong)UILabel *NameLabel;

/** 性别*/
@property(nonatomic,strong)UIImageView *sexIMG;

/** 地址*/
@property(nonatomic,strong)UILabel *AdressLabel;
@end

@implementation MSMeQRcodeController

- (int)navBarBottom {
    if ([WRNavigationBar isIphoneX]) {
        return 88;
    } else {
        return 64;
    }
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
    dispatch_async(dispatch_get_main_queue(), ^{
        
//        [self relodata];
        
        [self Relodata];
        
    });
}

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:YES];
    self.navigationController.navigationBar.hidden = YES;
    
}
- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self CreateNavigationBar];
    
    [self CreatView];
    
    
}
- (void)Relodata{
    NSDictionary * params = @{@"uid":[WYCAccountTool unarchiveuid]};
    
    //    [HTTPRequest POST:MSGetUserInfo params:params succeed:^(id responseObject) {
    //
    //    } failure:^(NSError *error) {
    //
    //    }];
    //    WYCLog(@"-------%@",params);
    AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
    //申明返回的结果是json类型
    manager.responseSerializer = [AFJSONResponseSerializer serializer];
    //申明请求的数据是json类型
    manager.requestSerializer = [AFJSONRequestSerializer serializer];
    //如果报接受类型不一致请替换一致text/html或别的
    manager.responseSerializer.acceptableContentTypes = [NSSet setWithObjects:@"application/json", @"text/plain", @"text/javascript", @"text/json", @"text/html",@"Type-Text",@"Content-Type", nil];
    manager.requestSerializer = [AFHTTPRequestSerializer serializer];
    //发送网络请求(请求方式为POST)
    [manager POST:@"http://192.168.50.154/mu_app_war/user/GetUserInfo" parameters:params progress:^(NSProgress * _Nonnull uploadProgress) {
        
    } success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
        WYCLog(@"-------%@",responseObject);
        if (CodeStr) {
            [self.photoIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",responseObject[@"data"][@"user"][@"avatarUrl"]]] placeholderImage:[UIImage imageNamed:@"我的占位头像"]];
            
            self.NameLabel.text = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"user"][@"userName"]];
            
            
            NSString * genderStr = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"user"][@"gender"]];
            if ([genderStr isEqualToString:@"0"]) {
                self.sexIMG.image = [UIImage imageNamed:@"女"];
            }else{
                self.sexIMG.image = [UIImage imageNamed:@"男"];
            }
            
            self.AdressLabel.text = [NSString stringWithFormat:@"%@",responseObject[@"data"][@"user"][@"country"]];
        }else{
            
            [MBManager showBriefAlert:responseObject[@"msg"]];
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
    }];
}
- (void)CreatView{
    
    /** 背景*/
    UIView * BackView = [[UILabel alloc] initWithFrame:CGRectMake(100 * px, 300 * px, ScreenWidth - 200 * px, 1200 * px)];
    BackView.layer.cornerRadius = 50 * px;
    BackView.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:BackView];
    
    
    /** 头像*/
    UIImageView * photoIMG = [[UIImageView alloc] initWithFrame:CGRectMake(50 * px, 50 * px, 120 * px, 120 * px)];
    photoIMG.layer.cornerRadius = 60 * px;
    photoIMG.layer.masksToBounds = YES;
    photoIMG.image = [UIImage imageNamed:@"财务-挂账结算"];
//    [BackView addSubview:photoIMG];
    self.photoIMG = photoIMG;
    
    /** 名称*/
    UILabel * NameLabel = [[UILabel alloc] initWithFrame:CGRectMake(CGRectGetMaxX(photoIMG.frame) + 20 * px, photoIMG.y + 20 * px, 120 * px, 50 * px)];
    NameLabel.textColor = [UIColor blackColor];
    NameLabel.text = @"宋阳";
    NameLabel.textAlignment = NSTextAlignmentLeft;
    NameLabel.font = [UIFont systemFontOfSize:SYRealValue(28 / 2)];
//    [BackView addSubview:NameLabel];
//    self.NameLabel = NameLabel;
    
    /** 性别*/
    UIImageView * sexIMG = [[UIImageView alloc] initWithFrame:CGRectMake(CGRectGetMaxX(NameLabel.frame), NameLabel.y, 40 * px, 40 * px)];
    sexIMG.image = [UIImage imageNamed:@"搜索"];
//    [BackView addSubview:sexIMG];
//    self.sexIMG = sexIMG;
    
    
    /** 名称*/
    UILabel * AdressLabel = [[UILabel alloc] initWithFrame:CGRectMake(NameLabel.x, CGRectGetMaxY(NameLabel.frame), 240 * px, 40 * px)];
    AdressLabel.textColor = [UIColor grayColor];
    AdressLabel.text = @"北京 海淀";
    AdressLabel.textAlignment = NSTextAlignmentLeft;
    AdressLabel.font = [UIFont systemFontOfSize:SYRealValue(26 / 2)];
//    [BackView addSubview:AdressLabel];
    self.AdressLabel = AdressLabel;
    
    
    /** 性别*/
    UIImageView * QRcodeIMG = [[UIImageView alloc] initWithFrame:CGRectMake(100 * px, CGRectGetMaxY(AdressLabel.frame) + 100 * px, BackView.width - 200 * px, BackView.width - 200 * px)];
    WYCLog(@"-------%@",self.qrcodeImg);
    [QRcodeIMG sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@",self.qrcodeImg]] placeholderImage:[UIImage imageNamed:@"我的占位图片"]];
    [BackView addSubview:QRcodeIMG];
    
    
    /** 提示*/
    UILabel * TipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, CGRectGetMaxY(QRcodeIMG.frame) + 30 * px, BackView.width, NameLabel.height)];
    TipsLabel.textColor = AdressLabel.textColor;
    TipsLabel.text = @"扫一扫上面的二维码给我评价";
    TipsLabel.textAlignment = NSTextAlignmentCenter;
    TipsLabel.font = AdressLabel.font;
    [BackView addSubview:TipsLabel];
}

- (void)CreateNavigationBar{
    
    self.view.backgroundColor = backgroundcolor;
    naviagtionBar = [[CustomNavigationBar alloc] initWithFrame:CGRectMake(0, 0, ScreenWidth, [self navBarBottom])];
    [self.view addSubview:naviagtionBar];
    naviagtionBar.titleLabel.text = @"我的二维码";
    naviagtionBar.rightBtn.hidden = YES;
    naviagtionBar.rightBtnTitle.hidden = YES;
    [self.view addSubview:naviagtionBar];
    
    [naviagtionBar.leftBtn setImage:[UIImage imageNamed:@"左箭头"] forState:UIControlStateNormal];
    [naviagtionBar.leftBtn addTarget:self action:@selector(backClick) forControlEvents:UIControlEventTouchUpInside];
    
}
- (void)backClick{
    
    [self.navigationController popViewControllerAnimated:NO];
}
@end
